
/**
 * 根据老状态生成当前状态能变更到的状态
 */
function initNewState(){
	var old = $('#orderStateOld').val();
	var $newSel = $('<select/>').attr({
		'id':'newOrderStateSel',
	}).addClass('form-control');
	var options = $('#oldOrderStateSel').find('option');
	$.each(options,function(index,item){
		if(item.value != old){
			var $op = $('<option/>').attr('value',item.value).text(item.text);
			$newSel.append($op);
		}
	});
	$('#newStateDiv').append($newSel);
	$('#newOrderStateSel').find('option[value="'+old+'"]').remove();
}

function saveNewState(){
	var remarks = $('#remarks').val();
	var oldState = $('#orderStateOld').val();
	var newState = $('#newOrderStateSel').val();
	//校验订单状态的修改是否满足规则
	
	if(remarks == null || remarks.length == 0){
		MsgBox.confirm("请填写备注，即手动修改订单状态原因等", "提示", function(){
			$('#remarks')[0].focus();
		});
	}else{
		var oldTxt = $('#oldOrderStateSel').find('option[value="'+oldState+'"]').text();
		var newTxt = $('#newOrderStateSel').find('option[value="'+newState+'"]').text();
		MsgBox.confirm("确认将订单状态由【"+
				"<span style='color:red;'>"+oldTxt+"</span>"
				+"】修改为【"+
				"<span style='color:red;'>"+newTxt+"</span>"
				+"】", "提示", function(){
			editStateAjax.addParam('orderId',$('#stateOrderId').text());
			editStateAjax.addParam('state',newState);
			editStateAjax.addParam('remarks',remarks);
			editStateAjax.send();
		});
	}
}

function onEditStateSucc(re){
	if(re.success || re.success == 'true'){
		$.messager.success("修改订单状态成功");
		refreshDetailPage();
		setTimeout("closeEditStatePage()", 2000);
	}
}

function closeEditStatePage(){
	$('#closeEditStateBtn').click();
}